package edu.cmu.cs.cs214.hw9.client.controllers;

import java.util.List;
import java.util.Observable;

import edu.cmu.cs.cs214.hw9.datatypes.Backend;
import edu.cmu.cs.cs214.hw9.datatypes.Status;
import edu.cmu.cs.cs214.hw9.datatypes.User;

/**
 * An adapter to allow backend data to be cached.
 * 
 * Methods are exactly the same as the {@link Backend}, with the exception that 
 * this caches data.
 */
public class BackendCacheAdapter extends Observable {
	private Backend backend;
	
	public BackendCacheAdapter(Backend backend) {
		this.backend = backend;
	}

	/*
	 * I think these should be cached. Not sure about the others though.
	 */
	public List<User> getUsers() {
		return backend.getUsers();
	}
	
	public User getUser(String email) {
		return backend.getUser(email);
	}
	
	public List<Status> getStatuses(User u) {
		return backend.getStatuses(u);
	}
	
	public List<User> getFriends(User u) {
		return backend.getFriends(u);
	}
	
	public List<Status> getMostRecentFriendUpdates(User u, int n) {
		return backend.getMostRecentFriendUpdates(u, n);
	}
	/*
	 * End cache todo.
	 */
	
	public boolean register(User u) {
		return backend.register(u);
	}

	public boolean removeUser(User u) {
		return backend.removeUser(u);
	}
	
	public boolean storeStatus(Status s) {
		return backend.storeStatus(s);
	}

	public boolean removeMostRecentStatus(User u) {
		return backend.removeMostRecentStatus(u);
	}

	public boolean requestFriend(User requester, User requestee) {
		return backend.requestFriend(requester, requestee);
	}

	public boolean removeFriend(User u1, User u2) {
		return backend.removeFriend(u1, u2);
	}
	
	public boolean login(String email, String pwd) {
		return backend.login(email, pwd);
	}
	
	public boolean areFriends(User u1, User u2) {
		return backend.areFriends(u1, u2);
	}
	
	public List<User> getFriendRequests(User user) {
		return backend.getFriendRequests(user);
	}
	
	/**
	 * As per interface docs, should not be used in production code. 
	 */
	public boolean storeFriend(User u1, User u2) {
		return backend.storeFriend(u1, u2);
	}
}
